package com.cts.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cts.constant.CommentConstant;
import com.cts.entity.Moment;
import com.cts.mapper.MomentMapper;
import com.cts.model.dto.MomentDTO;
import com.cts.model.vo.MomentVO;
import com.cts.model.vo.PageResultVO;
import com.cts.service.MomentService;
import com.mysql.cj.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author tongshengchen
* @description 针对表【moment】的数据库操作Service实现
* @createDate 2023-02-06 12:25:57
*/
@Service
public class MomentServiceImpl extends ServiceImpl<MomentMapper, Moment>
    implements MomentService {

    @Autowired
    MomentMapper momentMapper;

    @Override
    public PageResultVO<Moment> getMomentList(MomentDTO momentDTO) {
        LambdaQueryWrapper<Moment> momentLambdaQueryWrapper = new LambdaQueryWrapper<>();
        momentLambdaQueryWrapper.like(!StringUtils.isNullOrEmpty(momentDTO.getContent()), Moment::getContent, momentDTO.getContent());
        Page<Moment> page = new Page<>(momentDTO.getPageNo(), momentDTO.getPageSize());
        Page<Moment> momentPage = momentMapper.selectPage(page, momentLambdaQueryWrapper);
        return new PageResultVO(momentPage.getTotal(), momentPage.getRecords());
    }

    @Override
    public Boolean publishMoment(Integer id, Boolean isPublished) {
        Boolean result = momentMapper.publishMoment(id, isPublished);
        return result;
    }
}




